/******************************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd. 		              */
/*																              */
/*	NAME	  = t__cups_parse_head.c						              */
/*	NOTE	  = 												              */
/*	DATE	  = 2014/11/25 by geyh								              */
/******************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "apmtest_cunit.h"
#include <cups/cups_core.h>
#include <cups/cups_comm.h>
#include <apmtest_comm.h>
#include <cups/config.h>

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

static void __case1(void)
{
    int i_ret = FR_SUCC;
    Frbyte_Packet *p_st_data = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *)"\x2e\x02\x30\x34\x34\x36\x31\x34\x32\x32\x36\x35\x31\x30\x20\x20\x20\x30\x30\x30\x31\x30\x30\x30\x30\x20\x20\x20\x00\x00\x00\x00\x30\x30\x30\x30\x30\x30\x30\x30\x00\x30\x30\x30\x30\x30\x30\x32\x30\x30\xe2\x3a\x44\xc1\xb8\xe0\x18\x12\x00\x00\x00\x00\x10\x00\x00\x81", 66);
    char arr_dest_id[11+1] = {0};
    char arr_src_id[11+1] = {0};
    char arr_trans_info[8+1] = {0};
    char arr_msg_type[4+1] = {0};
    char arr_bitmap[16+1] = {0};
    unsigned int ui_bitmap_len = 0;
    unsigned int ui_rej_code = 0;

    i_ret = cups_parse_head(p_st_data
                            , arr_dest_id
                            , arr_src_id
                            , arr_trans_info
                            , arr_msg_type
                            , arr_bitmap
                            , &ui_bitmap_len
                            , &ui_rej_code);

    CU_ASSERT_STRING_EQUAL(arr_dest_id, "14226510");
    CU_ASSERT_STRING_EQUAL(arr_src_id, "00010000");
    CU_ASSERT_STRING_EQUAL(arr_trans_info, "00000000");
    CU_ASSERT_STRING_EQUAL(arr_msg_type, "0200");
    CU_ASSERT_EQUAL(ui_bitmap_len, 16);
    CU_ASSERT_EQUAL(ui_rej_code, 0);
    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    bytebuff_free(&p_st_data);

    return;
}

static void __case2(void)
{
    int i_ret = FR_SUCC;
    Frbyte_Packet *p_st_data = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *)"\x2e\x02\x30\x34\x34\x36\x31\x34\x32\x32\x36\x35\x31\x30\x20\x20\x20\x30\x30\x30\x31\x30\x30\x30\x30\x20\x20\x20\x00\x00\x00\x00\x30\x30\x30\x30\x30\x30\x30\x30\x00\x30\x30\x30\x30\x30\x30\x32\x30\x30\xe2\x3a\x44\xc1\xb8\xe0\x18\x12\x00\x00\x00\x00\x10\x00\x00\x81", 57);
    char arr_dest_id[11+1] = {0};
    char arr_src_id[11+1] = {0};
    char arr_trans_info[8+1] = {0};
    char arr_msg_type[4+1] = {0};
    char arr_bitmap[16+1] = {0};
    unsigned int ui_bitmap_len = 0;
    unsigned int ui_rej_code = 0;

    i_ret = cups_parse_head(p_st_data
                            , arr_dest_id
                            , arr_src_id
                            , arr_trans_info
                            , arr_msg_type
                            , arr_bitmap
                            , &ui_bitmap_len
                            , &ui_rej_code);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
    bytebuff_free(&p_st_data);

    return;
}

static void __case3(void)
{
    int i_ret = FR_SUCC;
    Frbyte_Packet *p_st_data = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *)"\x2e\x02\x30\x34\x34\x36\x31\x34\x32\x32\x36\x35\x31\x30\x20\x20\x20\x30\x30\x30\x31\x30\x30\x30\x30\x20\x20\x20\x00\x00\x00\x00\x30\x30\x30\x30\x30\x30\x30\x30\x00\x30\x30\x30\x30\x30\x30\x32\x30\x30\xe2\x3a\x44\xc1\xb8\xe0\x18\x12\x00\x00\x00\x00\x10\x00\x00\x81", 65);
    char arr_dest_id[11+1] = {0};
    char arr_src_id[11+1] = {0};
    char arr_trans_info[8+1] = {0};
    char arr_msg_type[4+1] = {0};
    char arr_bitmap[16+1] = {0};
    unsigned int ui_bitmap_len = 0;
    unsigned int ui_rej_code = 0;

    i_ret = cups_parse_head(p_st_data
                            , arr_dest_id
                            , arr_src_id
                            , arr_trans_info
                            , arr_msg_type
                            , arr_bitmap
                            , &ui_bitmap_len
                            , &ui_rej_code);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
    bytebuff_free(&p_st_data);

    return;
}

static void __case4(void)
{
    int i_ret = FR_SUCC;
    Frbyte_Packet *p_st_data = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *)"\x2e\x02\x30\x34\x34\x36\x31\x34\x32\x32\x36\x35\x31\x30\x20\x20\x20\x30\x30\x30\x31\x30\x30\x30\x30\x20\x20\x20\x00\x00\x00\x00\x30\x30\x30\x30\x30\x30\x30\x30\x00\x30\x30\x30\x30\x30\x30\x32\x30\x30\x62\x3a\x44\xc1\xb8\xe0\x18\x12\x00\x00\x00\x00\x10\x00\x00\x81", 66);
    char arr_dest_id[11+1] = {0};
    char arr_src_id[11+1] = {0};
    char arr_trans_info[8+1] = {0};
    char arr_msg_type[4+1] = {0};
    char arr_bitmap[16+1] = {0};
    unsigned int ui_bitmap_len = 0;
    unsigned int ui_rej_code = 0;

    i_ret = cups_parse_head(p_st_data
                            , arr_dest_id
                            , arr_src_id
                            , arr_trans_info
                            , arr_msg_type
                            , arr_bitmap
                            , &ui_bitmap_len
                            , &ui_rej_code);

    CU_ASSERT_STRING_EQUAL(arr_dest_id, "14226510");
    CU_ASSERT_STRING_EQUAL(arr_src_id, "00010000");
    CU_ASSERT_STRING_EQUAL(arr_trans_info, "00000000");
    CU_ASSERT_STRING_EQUAL(arr_msg_type, "0200");
    CU_ASSERT_EQUAL(ui_bitmap_len, 8);
    CU_ASSERT_EQUAL(ui_rej_code, 0);
    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    bytebuff_free(&p_st_data);

    return;
}

static void __case5(void)
{
    int i_ret = FR_SUCC;
    Frbyte_Packet *p_st_data = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *)"\x22\x02\x30\x34\x34\x36\x31\x34\x32\x32\x36\x35\x31\x30\x20\x20\x20\x30\x30\x30\x31\x30\x30\x30\x30\x20\x20\x20\x00\x00\x00\x00\x30\x30\x30\x30\x30\x30\x30\x30\x00\x30\x30\x30\x30\x30\x30\x32\x30\x30\xe2\x3a\x44\xc1\xb8\xe0\x18\x12\x00\x00\x00\x00\x10\x00\x00\x81", 66);
    char arr_dest_id[11+1] = {0};
    char arr_src_id[11+1] = {0};
    char arr_trans_info[8+1] = {0};
    char arr_msg_type[4+1] = {0};
    char arr_bitmap[16+1] = {0};
    unsigned int ui_bitmap_len = 0;
    unsigned int ui_rej_code = 0;

    i_ret = cups_parse_head(p_st_data
                            , arr_dest_id
                            , arr_src_id
                            , arr_trans_info
                            , arr_msg_type
                            , arr_bitmap
                            , &ui_bitmap_len
                            , &ui_rej_code);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
    bytebuff_free(&p_st_data);

    return;
}


int add_suite_cups_parse_head(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" cups_parse_head()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL ||
        CU_add_test(pSuite, "case4", __case4) == NULL ||
        CU_add_test(pSuite, "case5", __case5) == NULL
        )
        return FR_FAIL;

    return FR_SUCC;
}
